<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/view/inc/sys.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>${projectName}-业务日志</title>
<jsp:include page="/WEB-INF/view/inc/css.jsp"></jsp:include>
</head>
<body>
	<jsp:include page="/WEB-INF/view/inc/header.jsp"></jsp:include>
	<div class="container">
		<jsp:include page="/WEB-INF/view/admin/comm/left.jsp">
			<jsp:param name="first" value="prj"/>
			<jsp:param name="second" value="bizLogManager"/>
		</jsp:include>
		<div class="c-right">
			<div class="${bodyMainClass}">
				<div class="panel-heading panel-heading-tool">
					<div class="row">
						<div class="col-sm-5 title">项目 / <b>业务日志</b></div>
						<div class="col-sm-7 text-right">
							<div class="btn-group">
						  		<a href="javascript:location.reload()" class="btn btn-default btn-sm">刷新</a>
							</div>
						</div>
					</div>
				</div>
				<div class="panel-body">
				  	<div class="row layout">
				  		<div class="col-sm-6 left">
				  			<div class="table-tool-panel">
				  			<div class="row">
								<div class="col-sm-11">
									<div class="enter-panel">
									<input type="text" class="form-control input-sm w-80" id="beginTime" placeholder="开始时间" value="" onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})">
									<input type="text" class="form-control input-sm w-80" id="endTime" placeholder="结束时间" value="" onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})">
							  		<input type="text" class="form-control input-sm w-60" id="reqParam1" placeholder="reqParam1" value="" title="reqParam1">
							  		<input type="text" class="form-control input-sm w-60" id="reqParam2" placeholder="reqParam2" value="" title="reqParam2">
							  		<input type="text" class="form-control input-sm w-60" id="reqParam3" placeholder="reqParam3" value="" title="reqParam3">
							  		<button type="button" class="btn btn-sm btn-default enter-fn" onclick="info.loadInfo(1)">查询</button>
						  			</div>
								</div>
								<div class="col-sm-1 text-right">
								  	<div class="btn-group">
								  	</div>
								</div>
							</div>
							</div>
							<div id="infoPanel" class="table-panel"></div>
							<div id="infoPage" class="table-page-panel"></div>
				  		</div>
				  		<div class="col-sm-6 right">
				  			<div id="rightInfoMsg" class="right-msg-panel"><label class="label label-warning">暂无详细业务日志信息~</label></div>
				  			<div id="rightInfo" class="right-panel" style="display: none;">
					  			<div class="table-tool-panel">
						  			<div class="row">
										<div class="col-sm-11 text-muted" id="rightInfoTitle">
										</div>
										<div class="col-sm-1 text-right">
										  	<div class="btn-group">
										  		<%-- <a href="javascript:;" class="btn btn-info btn-sm" onclick="right.releaseAll()">全部署</a>
										  		<a href="javascript:;" class="btn btn-success btn-sm" onclick="right.edit()">+ 客户端</a>
										  		<a href="${webroot}/prjMonitor/f-view/manager.shtml?prjId=${param.prjId}" class="btn btn-default btn-sm" target="_blank">看服务</a> --%>
										  	</div>
										</div>
									</div>
							  	</div>
								<div id="rightPanel" class="table-panel"></div>
								<div id="rightPage" class="table-page-panel"></div>
							</div>
				  		</div>
				  	</div>
				</div>
			</div>
		</div>
		<br clear="all">
	</div>
	<jsp:include page="/WEB-INF/view/inc/js.jsp"></jsp:include>
	<jsp:include page="/WEB-INF/view/inc/utils/page.jsp"></jsp:include>
	<jsp:include page="/WEB-INF/view/inc/utils/my97date.jsp"></jsp:include>
<script type="text/javascript">
var infoPage = undefined;
var info = {
		loadInfo : function(page) {
			if (page == 1) {
				right.traceId = undefined;
			}
			if(!infoPage) {
				infoPage = new Page('infoPage', info.loadInfo, 'infoPanel', 'infoPage');
				infoPage.beginString = ['<table class="table table-striped table-hover"><thead><tr class="info">',
				                         '<th>traceId</th>',
				                         '<th>参数1</th>',
				                         '<th>参数2</th>',
				                         '<th>参数3</th>',
				                         '<th>请求时间</th>',
				                         '<th width="60">操作</th>',
				                         '</tr></thead><tbody>'].join('');
				infoPage.endString = '</tbody></table>';
			}
			if(page != undefined)
				infoPage.page = page;

			JUtil.ajax({
				url : '${webroot}/bizLog/f-json/pageQuery.shtml',
				data : { page:infoPage.page, size:infoPage.size, beginTime:$('#beginTime').val(), endTime:$('#endTime').val(),
					reqParam1: $('#reqParam1').val(), reqParam2: $('#reqParam2').val(), reqParam3: $('#reqParam3').val()},
				beforeSend: function(){ infoPage.beforeSend('加载信息中...'); },
				error : function(json){ infoPage.error('加载信息出错了!'); },
				success : function(json){
					if(json.code === 0) {
						function getResult(obj) {
							var trClass = '';
							if(right.traceId === undefined) {
								//为第一次进来，默认加载发布的项
								right.traceId = obj.traceId;
								right.loadInfo();
								trClass = 'success';
							}
							var traceId = obj.traceId;
							if (traceId.length > 30) {
								traceId = '...' + traceId.substring(traceId.length - 10, traceId.length);
							}
							return ['<tr class="',trClass,'">',
							    	'<td>',traceId,'</td>',
							    	'<td>',obj.reqParam1,'</td>',
							    	'<td>',obj.reqParam2,'</td>',
							    	'<td>',obj.reqParam3,'</td>',
							    	'<td>',obj.reqTime,'</td>',
							    	'<td><a class="text-success" href="javascript:;" onclick="info.look(this, \'',obj.traceId,'\')" title="查看详细信息">详情</a>',
									'</td>',
								'</tr>'].join('');
						}
						infoPage.operate(json.body, { resultFn:getResult, dataNull:'没有记录噢' });
						JUtil.sys.initOptMore();
					}
					else alert(JUtil.msg.ajaxErr);
				}
			});
		},
		look: function(_this, traceId) {
			var tr = $(_this).parent().parent();
			tr.parent().find('tr').each(function(i, obj) {
				$(obj).removeClass('success');
			});
			tr.addClass('success');
			right.traceId = traceId;
			right.loadInfo();
		}
};

var rightPage = undefined;
var right = {
		//获取用户信息
		loadInfo : function() {
			if(right.traceId != undefined) {
				$('#rightInfo').css('display', 'block');
				$('#rightInfoMsg').css('display', 'none');
			}
			$('#rightInfoTitle').html('<small>traceId：</small><span class="label label-warning">' + right.traceId + '</span>');
			var panel = $('#rightPanel').empty();
			JUtil.ajax({
				url : '${webroot}/bizLog/f-json/get.shtml',
				data : {
					traceId: right.traceId
				},
				success : function(json) {
					if (json.code === 0) {
						var content = [];
						$.each(json.body.spanIds, function(i, spanId) {
							content.push('<div><table class="table table-striped table-hover"><thead><tr class="info">',
			                '<th>key</th>',
			                '<th>value</th>',
			                '</tr></thead><tbody>');
							$.each(json.body.dtls, function(j, obj) {
								if (obj.spanId == spanId) {
									content.push('<tr>',
										'<td>',obj.reqKey,'</td>',
										'<td>',obj.reqValue,'</td>',
										'</tr>');
								}
						});
						content.push('</tbody></table></div>');
						});
						panel.append(content.join(''));
					}
					else if (json.code === -1)
						message(JUtil.msg.ajaxErr);
					else
						message(json.message);
				}
			});
		}
};
$(function() {
	$('#beginTime').val(JUtil.date.formatStr(JUtil.date.getDateAddHour(JUtil.date.getDate(), -24 * 3)));
	$('#endTime').val(JUtil.date.formatStr(JUtil.date.getDate()));
	info.loadInfo(1);
});
</script>
</body>
</html>